package com.shawn.baseappbygroovydsl.component

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
import com.shawn.baseappbygroovydsl.utils.ExtensionCommon.dp

/**
 * @author Secret
 * @since 2023/6/2
 */
class ItemDecorationBottomOffset : ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)
        val adapter = parent.adapter
        adapter?.let {
            val position = parent.getChildAdapterPosition(view)
            if (position == 1) {
                outRect.bottom = 10f.dp.toInt()
                outRect.top = -10f.dp.toInt()
            } else if (position > 0) {
                outRect.bottom = 10f.dp.toInt()
            }
        }
    }

}